package com.example.societiesSystem.controller;


import cn.hutool.core.date.LocalDateTimeUtil;
import com.example.societiesSystem.common.R;
import com.example.societiesSystem.entity.SocietiesType;
import com.example.societiesSystem.service.ISocietiesTypeService;
import com.example.societiesSystem.service.ITeamsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 社团类型 前端控制器
 * </p>
 *
 * @author 周欢
 * @since 2025-05-27
 */
@Api(tags = "社团类型 前端控制器")
@CrossOrigin
@RestController
@RequestMapping("teamTypes")
public class SocietiesTypeController {


    @Resource
    private ISocietiesTypeService societiesTypeService;

    @ApiOperation(value = "分页查询社团类型")
    @GetMapping("/page")
    public R pageAll(@RequestParam("pageIndex") Long pageIndex
            , @RequestParam("pageSize") Long pageSize
            , @RequestParam(value = "name", required = false) String name)
    {
        return R.data(societiesTypeService.pageAll(pageIndex,pageSize,name));
    }

    @ApiOperation(value = "查询所有社团类型")
    @GetMapping("/all")
    public R getAll() {
        return R.data(societiesTypeService.getBaseMapper().selectList(null));
    }

    @ApiOperation(value = "社团类型添加")
    @PostMapping("/add")
    public R add(@RequestBody SocietiesType societiesType) {
        societiesType.setCreateTime(LocalDateTimeUtil.now());
        return R.data(societiesTypeService.save(societiesType));
    }

    @ApiOperation(value = "社团类型修改")
    @PostMapping("/upd")
    public R upd(@RequestBody SocietiesType societiesType) {
        return R.data(societiesTypeService.updateById(societiesType));
    }

    @ApiOperation(value = "社团类型删除")
    @PostMapping("/del")
    public R del(@RequestBody SocietiesType societiesType) {
        return R.data(societiesTypeService.removeById(societiesType));
    }
}
